import pandas as pd


def main():
    # 读取文本文件
    df = pd.read_csv("cluster_info.txt", sep=",", header=None)

    # 假设文件的格式为：Cluster: x, Max Point: [a, b], Distance: c, Num of Square Points: d, Radius: e
    # 我们需要处理字符串，提取所需的信息
    def process_column(row):
        cluster = row[0].split(": ")[1]
        # 修正列表字符串的格式，添加必要的逗号分隔
        max_point_str = (
            row[1]
            .split(": ")[1]
            .strip("[]")
            .replace(" ", "")
            .replace(",", ", ")
            .strip()
        )
        if not max_point_str:  # 处理可能的空字符串情况
            max_point = [None, None]
        else:
            max_point = eval(f"[{max_point_str}]")  # 将字符串表示的列表转换为列表
        distance = float(row[2].split(": ")[1])
        num_square_points = int(row[3].split(": ")[1])
        radius = float(row[4].split(": ")[1])
        return pd.Series(
            [cluster, max_point[0], max_point[1], distance, num_square_points, radius]
        )

    df = df.apply(process_column, axis=1)
    df.columns = [
        "Cluster",
        "Max Point X",
        "Max Point Y",
        "Distance",
        "Num of Square Points",
        "Radius",
    ]
    # 将数据存储为 Excel 文件
    df.to_excel("cluster_info.xlsx", index=False)


if __name__ == "__main__":
    main()
